package com.nobody.facepk.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.nobody.facepk.model.Focus;
import com.nobody.facepk.model.User;
import com.nobody.facepk.model.UserData;
import com.nobody.facepk.model.UserDataType;
import com.trg.dao.hibernate.GeneralDAO;
import com.trg.search.Search;

@Component
public class UserDao {
	private GeneralDAO generalDao;
	
	public List<Focus> getMyFocus(Long userId){
		Search search = new Search(Focus.class);
		search.addFilterEqual("userId", userId);
		return this.generalDao.search(search);
	}
	
	public List<Focus> getFocused(Long userId){
		Search search = new Search(Focus.class);
		search.addFilterEqual("targetId", userId);
		return this.generalDao.search(search);
	}
	
	public User getUserByMobile(String mobile) {
		Search search = new Search(User.class);
		search.addFilterEqual("mobile", mobile);
		User user = (User)this.generalDao.searchUnique(search);
		return user;
	}
	
	public UserData getUserData(Long userId, UserDataType type) {
		Search search = new Search(UserData.class);
		search.addFilterEqual("userId", userId);
		search.addFilterEqual("type", type);
		return (UserData)this.generalDao.searchUnique(search);
	}
	
	@Autowired
	public void setGeneralDao(GeneralDAO generalDao) {
		this.generalDao = generalDao;
	}
}
